public class Student {
    private String name;
    private int age;
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {  //1. 如果this和obj指向同一个对象, 则返回true;
            return true;
        }
        if (obj instanceof Student) {  //2. 如果this和obj指向不同对象, 而且obj是Student类型的
            if (this.age == ((Student) obj).getAge() && this.name == ((Student) obj).getName()) {
                return true;
            }
            return false;
        }
        return false;
    }
}

